﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace GrandMan.Models
{
    [Serializable]
    public class MenuModel
    {
        public List<Menu> MenuList { get; set; }

        public MenuModel()
        {
            MenuList = new List<Menu>() 
            {
                new Menu(){ Title = "主页管理" , Key = "" , SubList = new List<Menu>()
                {
                    new Menu(){ Title = "基础资料" , Key = "/Admin/BaseInfo"},
                    new Menu(){ Title = "管理团队" , Key = "/Admin/HomeTeam"},
                    new Menu(){ Title = "服务品牌" , Key = "/Admin/HomePartner"},
                }},
                new Menu(){ Title = "文章管理" , Key = "", SubList = new List<Menu>()
                {
                    new Menu(){ Title = "公司简介" , Key = "/Admin/Company"},
                    new Menu(){ Title = "专家团队" , Key = "/Admin/Team"},
                    new Menu(){ Title = "最新动态" , Key = "/Admin/News"},
                    new Menu(){ Title = "行业资讯" , Key = "/Admin/Info"},
                    new Menu(){ Title = "联系我们" , Key = "/Admin/Contact"},
                }},
            };
        }

        public void Select(string title) 
        {
            foreach (var menu in MenuList)
            {
                menu.IsSelect = false;
                foreach (var subMenu in menu.SubList)
                {
                    subMenu.IsSelect = false;
                    if (subMenu.Title == title)
                    {
                        subMenu.IsSelect = true;
                        menu.IsSelect = true;
                    }
                }
            }
        }
    }

    [Serializable]
    public class Menu
    {
        public string Title { get; set; }
        public string Key { get; set; }
        public List<Menu> SubList { get; set; }
        public bool IsSelect { get; set; }

        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;
            if (!(obj is Menu))
                return false;
            Menu menu = (Menu)obj;
            return menu.Key.Equals(this.Key);
        }
    }
}